/**
 * JSON 扁平化
 * @param obj 原始对象
 * @param parentKey
 * @param result
 * @returns
 */
const JSONFlatten = (obj: any, parentKey = '', result: any = {}): any => {
  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      const newKey = parentKey ? `${parentKey}.${key}` : key
      if (typeof obj[key] === 'object' && obj[key] !== null) {
        JSONFlatten(obj[key], newKey, result)
      } else {
        result[newKey] = obj[key]
      }
    }
  }
  return result
}

export default JSONFlatten
